package com.ovhoo.vdm.vdm;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class VDMListAdapter extends BaseAdapter {
	private Activity context;
	private ArrayList<VDMQuote> quotes;
	private boolean inhibited;
	
	VDMListAdapter(Activity context) {	
		this.context=context;
		
		//Désactiver la liste en attendant que le contenu soit disponible
		this.inhibited = true;
		
		//Chargement des VDM.
        //ArrayList<Quote>  quotes =  VDMLoader.getLastPosts();
        //quotes =  VDMLoader.getLastPosts();
		 
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater=context.getLayoutInflater();
		View row = inflater.inflate(R.layout.quote, null);
		
		TextView message=(TextView)row.findViewById(R.id.message);
		TextView author=(TextView)row.findViewById(R.id.author);
		TextView agree=(TextView)row.findViewById(R.id.agree);
		TextView deserved=(TextView)row.findViewById(R.id.deserved);

		if (position < this.quotes.size()){
			VDMQuote _quote = this.quotes.get(position);
			System.out.println("VDM->VDMListAdapter::getView position=" + position);
			
			message.setText(_quote.getMessage());
			author.setText(_quote.getAuthor());
			agree.setText("" + _quote.getAgree());
			deserved.setText("" + _quote.getDeserved());
		}
		else {
			message.setText("Ca ne marche toujours pas VDM");
		}
					
		return(row);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (this.inhibited){
			return 0;
		}
		return this.quotes.size();
	}


	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void inhibit(boolean inhib){
		this.inhibited = inhib;
	}
	
	public void setQuotes(ArrayList<VDMQuote>  quotes){
		this.quotes = quotes;
		this.inhibit(false);
		//this.notifyDataSetChanged();
	}
}
